//
// Created by PC on 2023/7/28.
// 输入整数, 变成英语表示 十位个位之间无-连接
// 不限制整数的长度, 最大的量词就是billion, 每9位多一个billion
// 不考虑如下情况: 1. 多个0开头 2.输入英文字母
/*
123: one hundred twenty
1'234: one thousand two hundred thirty four
 12'345 twelve thousand three hundred forty five
 123'456 one hundred twenty three thousand four hundred fifty six
 1'234'567 one million two hundred thirty four thousand five hundred sixty seven
 1'234'567'890 one billion two hundred thirty four million five hundred sixty seven thousand eight hundred ninety
 1'000'000'000'000 	one trillion
 * */
//


#include <iostream>
#include <vector>

using namespace std;

string onetoten[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven",
                     "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
string tens[] = {"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
string units[] = {"thousand", "million", "billion", "trillion", "zillion", "jillion"};

int main()
{
//    cout<<sizeof (string);
//    for (int i = 0; i < 20; ++i)
//        printf("%d: %s\n", i,nums[i].c_str());
    string n = "1023156789934342305320";
//    n = "800000900";
//    n = "9011";
//    n = "880001000000000";
//    n = "880000000000000";
    n = "8800000000000000100000000010000000";
//    n = "1234567";
    // 计算需要分成带’分隔符的几段
    int nn = n.size() / 3;
    if (n.size() % 3 != 0) ++nn;
    // 将每三位一段存到数组中 从最高位的数段存在数组最低位 每段中的顺序也是倒置的
    string nums[nn];
    for (int j = 0; j < nn; ++j)
        nums[j] = "";
    int index = 0;
    for (int i = n.size() - 1; i >= 0; --i)
    {
        nums[index] += n[i];
        if ((n.size() - i) % 3 == 0)
            ++index;
    }
    // 倒序输出打印， 带‘分隔符的数字
    for (int k = nn - 1; k >= 0; --k)
    {
        for (int i = nums[k].size() - 1; i >= 0; --i)
        {
            cout << nums[k][i];
        }
        if (k > 0)
            cout << '\'';
    }
    cout << '\n';
    // words 用来保存转换成文字的数组, 每个字一个元素
    vector<string> words;
    // 当前数段全零的计数器
    int countZero = 0;
    // 从最高位开始往后看, 每一段3个数, 规则是固定的
    // 在每段中间要根据情况加量词 如: thousand million billion 最高就到billion
    for (int i = 0; i < nn; ++i)
    {
        // 如果当前段全零, 计数器++, 否则计数器清零
        countZero = nums[i] == "000" ? ++countZero : 0;
        // 每三段连续全000, 则加一个billion, 因为当前也是000, 直接跳过此次循环
        if (countZero == 3)
        {
            words.push_back(" billion");
            countZero = 0;
            continue;
            // 当前是000, 但下一段不是000, 要加量词, 然后跳过此次循环
        } else if (countZero > 0 && nums[i + 1] != "000")
        {
            words.push_back(" " + units[i % 3]);
            continue;
            // 当前是000, 而且下一段也是000, 跳过此次循环
        } else if (countZero > 0)
        {
            continue;
        }
        // 接下来处理 有数字的情况 也就是并非000的情况
        int len = nums[i].size();
        // 此段只有1个数 也就是只有个位数 那就到了最高位了 计算完直接跳过此次循环
        if (len == 1)
        {
            words.push_back(" " + onetoten[nums[i][0] - '0']);
//            continue;
        }

        // 每段只有3位 从1开始是因为个位数肯定存在
        for (int j = 1; j < nums[i].size(); ++j)
        {
            // 十位数 10-19
            if (j == 1 and nums[i][j] == '1')
            {
//                cout << endl << tens[nums[i][j] - '0'];
                words.push_back(" " + onetoten[nums[i][j] - '0' + 9 + nums[i][0] - '0']);
            } else if (j == 1 and nums[i][j] != '1')
            {
                // 20-99
                // 个位十位都有的情况 中间要加"-"
                if (nums[i][0] != '0' && nums[i][1] != '0')
                {
                    //个位数
                    words.push_back("-" + onetoten[nums[i][0] - '0']);
                    // 十位数
                    words.push_back(" " + tens[nums[i][1] - '0']);
                } else
                    // 只有个位或只有十位的情况
                {
                    //个位数
                    if (nums[i][0] != '0')
                        words.push_back(" " + onetoten[nums[i][0] - '0']);
                        // 十位数
                    else if (nums[i][1] != '0')
                        words.push_back(" " + tens[nums[i][1] - '0']);
                }
            }
                // 百位数
            else if (j == 2 and nums[i][2] != '0')
            {
//                cout << endl << onetoten[nums[i][j] - '0'] << " hundred";
                words.push_back(" hundred");
                words.push_back(" " + onetoten[nums[i][j] - '0']);
            }
        }
        // 设置这个条件目的:
        // i<nn-1防止在循环最后添加数量词
        // countZero==0 当前数段不是000
        // nums[i+1]!="000" 下一数段也不是000 才添加数词
        if (i < nn - 1 and countZero == 0 and nums[i + 1] != "000")
            words.push_back(" " + units[i % 3]);
    }
    for (int i = words.size() - 1; i >= 0; --i)
    {
        // 数组中每个字符串都是" "开头, 所以打印的第一个字符串要跳过" "再打印
        if (i == (words.size() - 1))
        {
            for (int j = 1; j < words[i].size(); ++j)
            {
                printf("%c", words[i][j]);
            }
        } else
            printf("%s", words[i].c_str());
    }

    return 0;
}